<div id="mood_form">
	<form method="post" action="cp.php?ac=doing" id="mood_addform">
		<div id="mood_statusinput" class="text_bg" style="z-index:1;">
			<textarea name="message" id="mood_message" onclick="hiddenmessage();" onKeyDown="checkMaxInput(this)" onKeyUp="checkMaxInput(this)" onpropertychange="if(this.value.length>100) this.value=this.value.substr(0,100)"  onBlur="checkMaxInput(this)" >你可以更新状态, 让好友们知道你在做什么...</textarea>
		</div>
		<div id="mood_updatebn">
			<span><input type="button" id="mood_add" name="add" value="发布" class="mes_pub" onclick="submitMessage();" style="z-index:20005;"/></span>
			<span><a href="javascript:;" class="add_face" onclick="statusFace();">表情</a></span>
			<span id="dis_wordnum" class="disnum">你还可以输入<strong id="wordnum" style="color:#2D63BB;">100</strong>字</span>
			<span id="mood_mystatus" >$space[spacenote]</span>
			<input type="hidden" name="addsubmit" value="true" />
			<input type="hidden" name="spacenote" value="true" />
			<input type="hidden" name="formhash" value="<!--{eval echo formhash();}-->" />
		</div>
	</form>
</div>

<script type="text/javascript">

	function checkMaxInput(obj)
	{
		var str = obj.value;
		var totalLength = 0;
		var list = str.split("");
		for(var i = 0; i < list.length; i++) {
			var s = list[i];
			if (s.match(/[\u0000-\u00ff]/g)) { //半角
				totalLength += 1; 
			} else if (s.match(/[\u4e00-\u9fa5]/g)) { //中文  
				totalLength += 1; 
			} else if (s.match(/[\uff00-\uffff]/g)) { //全角 
				totalLength +=1;
			}
		}
		$('wordnum').innerHTML = 100-totalLength;
		if(totalLength>100){ 
			obj.value=obj.value.substring(0,100);
		}
	}

	function submitMessage(){
		if($('mood_message').value != '你可以更新状态, 让好友们知道你在做什么...'){
			ajaxpost('mood_addform', 'reloadMood');$('mood_message').value='';
		}
	}
	function statusFace() {
		if($('mood_message').value == '你可以更新状态, 让好友们知道你在做什么...'){
			$('mood_message').value = '';
		}
		$('mood_statusinput').style.zIndex = '20005';
		$('mood_statusinput').className = 'text_bg';
		$('mood_add').style.display = 'block';

		var div = $('mood_face_bg');
		if(div) {
			div.parentNode.removeChild(div);
		}
		div = document.createElement('div');
		div.id = 'mood_face_bg';
		div.style.position = 'absolute';
		div.style.left = div.style.top = '0px';
		div.style.width = '100%';
		div.style.height = document.body.scrollHeight + 'px';
		div.style.backgroundColor = '#000';
		div.style.zIndex = 100;
		div.style.display = 'none';
		div.style.filter = 'alpha(opacity=0)';
		div.style.opacity = 0;
		div.onclick = function() {
			hiddenstatus();
		}
		$('append_parent').appendChild(div);

		if($('mood_message_menu') != null) {
			$('mood_message_menu').style.display = '';
			$('mood_add').style.display = 'block';
		} else {
			var faceDiv = document.createElement("div");
			faceDiv.id = 'mood_message_menu';
			faceDiv.className = 'facebox';
			faceDiv.style.position = 'absolute';
			var faceul = document.createElement("ul");
			for(i=1; i<31; i++) {
				getStatusFace(i, faceul);	
			}
			faceDiv.appendChild(faceul);
			$('append_parent').appendChild(faceDiv);
		}
		//定位菜单
		setMenuPosition('mood_message', 0);
		div.style.display = '';
	}

	function hiddenmessage(){
		if($('mood_message').value == '你可以更新状态, 让好友们知道你在做什么...'){
			$('mood_message').value = '';
		}
		var div = $('mood_face_bg');
		if(div) {
			div.parentNode.removeChild(div);
		}
		div = document.createElement('div');
		div.id = 'mood_face_bg';
		div.style.position = 'absolute';
		div.style.left = div.style.top = '0px';
		div.style.width = '100%';
		div.style.height = document.body.scrollHeight + 'px';
		div.style.backgroundColor = '#000';
		div.style.zIndex = 10000;
		div.style.display = 'none';
		div.style.filter = 'alpha(opacity=0)';
		div.style.opacity = 0;
		div.onclick = function() {
			hiddenstatus();
		}
		$('append_parent').appendChild(div);
		div.style.display = '';
	}

	function hiddenstatus() {
		if($('mood_message_menu'))
			$('mood_message_menu').style.display = 'none';
		$('mood_face_bg').style.display = 'none';
		$('mood_add').style.display = 'block';
		$('mood_statusinput').className = 'text_bg';
		if($('mood_message').value == ''){
			$('mood_message').value = '你可以更新状态, 让好友们知道你在做什么...';
		}
		$('mood_statusinput').style.zIndex = '1';
	}
	
	function getStatusFace(i, faceul) {
		var faceli = document.createElement("li");
		faceli.innerHTML = '<img src="image/face/'+i+'.gif" style="cursor:pointer; position:relative;" />';
		faceli.getElementsByTagName('img').item(0).onclick = function(){var faceText = '[em:'+i+':]'; if($('mood_message') != null) { insertContent('mood_message', faceText); }};
		faceul.appendChild(faceli);
	}
	
	function reloadMood(showid, result) {
		var x = new Ajax();
		x.get('cp.php?ac=doing&op=getmood', function(s){
			$('mood_mystatus').innerHTML = s;
		});
		hiddenstatus();
	}  
</script>